Skip to content

feat(history): 转录失败保留录音 + 历史「重新转录」(#613)#637

Merged
H-Chris233 merged 1 commit into
betafrom
feat/issue-613-retain-recording-retranscribe
Jun 11, 2026
Merged

feat(history): 转录失败保留录音 + 历史「重新转录」(#613)#637
H-Chris233 merged 1 commit into
betafrom
feat/issue-613-retain-recording-retranscribe

Conversation

@appergb

@appergb appergb commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

User description

背景

Closes #613。ASR 转录失败(网络错误 / 超时 / 引擎异常)时,当前各失败分支只 emit_capsule(Error)return Err不写历史 —— 即使用户开了「保留原始录音」,也无法在历史页找到这次会话、回放录音或重试。本 PR 让失败也能恢复。

改动清单

后端

  • coordinator/dictation_end.rs:新增 write_transcribe_failed_history 辅助函数;在 14 处真实转录失败分支(各 provider 的 Ok(Err) / 超时;不含 cancel / empty-transcript 分支)调用它写一条 transcribeFailed 历史。
    • 关键:history id 用 coordinator 的 session_id(而非新 UUID),与 recorder 旁路写盘的 recordings/<id>.wav 同名 —— 否则回放 / 重转会 404。
    • 仅在录音确已归档时写(读 audio_archive_active,沿用 empty-transcript「以实际归档状态为准」语义),未归档不写空壳记录。
  • coordinator.rsretranscribe_pcm(pcm) —— 复用 build_qa_asr_start,用当前 ASR provider 对一段 PCM 重新转录,统一覆盖流式(Volcengine/Bailian)+ 批处理(Whisper/Mimo/local-qwen/Foundry/sherpa)全部 provider,整段超时兜底。
  • persistence.rsHistoryStore::update_entry —— 原地按 id 替换历史条目(保持原位置),找不到返回 Ok(false)
  • commands/history.rsretranscribe_recording 命令 —— 校验 id → 读归档 wav → 取 PCM(跳过 44 字节 WAV 头)→ 重转 → 回写 rawTranscript/finalText 并清 error_code → 返回更新后的整条记录。已注册到 lib.rs

前端

  • lib/ipc.tsretranscribeRecording
  • pages/History.tsx:失败条目(有 errorCode)且录音仍在时显示「重新转录」按钮,loading 态防重复点击,成功后局部刷新该条。
  • i18nhistory.retranscribe / retranscribing / retranscribeFailed(zh-CN / en / ja / ko / zh-TW 全部同步)。

验收标准对照(issue #613

  • ASR 转录失败、录音已归档时写一条历史记录(errorCode = transcribeFailed
  • 该条目可播放 / 导出原始录音(复用现有 read_audio_recording,id 与 wav 对齐)
  • 历史详情提供「重新转录」按钮,对归档 wav 用当前 ASR provider 重转
  • 重转成功后更新 rawTranscript / finalText 并清除错误状态
  • 重转失败给出明确错误提示,保留原录音不丢失

取舍 / 待定(issue 里标为「不确定项」)

  • 未做自动二次润色:重转只跑 ASR。润色依赖 LLM 凭据且 issue 标为待定,留作后续。raw transcript 已恢复用户的话,核心价值已满足。
  • 重转使用当前 provider(非录音时的 provider),实现最简单可预测;如需「沿用原 provider」可后续加。
  • 未做重转次数限制 / 重试历史,issue 标为待定。
  • 失败时是否在未开「保留原始录音」时也自动保留录音 —— 本 PR 沿用现状(仅在已归档时写历史),是否放宽待产品/隐私确认。

测试情况

  • cargo check(macOS)✅
  • cargo test --lib:481 通过 ✅
  • npm run build(tsc + vite)✅
  • 真机实测待办:① 制造一次转录失败(断网 / 错误 endpoint),确认失败后历史里出现条目、可回放;② 点「重新转录」(恢复网络后)确认出字并刷新该条;③ 重转仍失败时确认错误提示且录音保留。

🤖 Generated with Claude Code


PR Type

Bug fix, Enhancement


Description

  • 转录失败时保留录音并写入历史

  • 新增「重新转录」功能,对归档录音重新ASR

  • 前端支持重新转录按钮及局部刷新


Diagram Walkthrough

flowchart LR
  A["语音录制"] --> B["ASR 转录"]
  B -- "失败" --> C["写入失败历史 (transcribeFailed)"]
  C --> D["历史页显示重新转录按钮"]
  D --> E["用户点击重新转录"]
  E --> F["读取归档 WAV (recordings/id.wav)"]
  F --> G["retranscribe_pcm (当前 ASR provider)"]
  G -- "成功" --> H["回写 rawTranscript / finalText,清除 errorCode"]
  G -- "失败" --> I["保留原文,显示错误提示"]
Loading

File Walkthrough

Relevant files
Enhancement
11 files
history.rs
add retranscribe_recording command for failed entries       
+60/-0   
coordinator.rs
add retranscribe_pcm method for re-transcription                 
+64/-0   
lib.rs
register retranscribe_recording command                                   
+1/-0     
persistence.rs
add update_entry to replace history entry in-place             
+14/-0   
en.ts
add i18n keys for retranscribe                                                     
+3/-0     
ja.ts
add i18n keys for retranscribe                                                     
+3/-0     
ko.ts
add i18n keys for retranscribe                                                     
+3/-0     
zh-CN.ts
add i18n keys for retranscribe                                                     
+3/-0     
zh-TW.ts
add i18n keys for retranscribe                                                     
+3/-0     
ipc.ts
add retranscribeRecording IPC function                                     
+11/-0   
History.tsx
add retranscribe button for failed entries                             
+37/-1   
Bug fix
1 files
dictation_end.rs
write failed transcription history on ASR error branches 
+52/-0   

ASR 转录失败时若本次录音已归档,写一条 transcribeFailed 历史记录,让用户能在
历史页回放原始录音并对其重新转录,不再丢失可恢复的语音内容。

后端:
- dictation_end: 新增 write_transcribe_failed_history 辅助函数,在 14 处真实
  转录失败分支(各 provider 的 Ok(Err)/超时;不含 cancel/empty 分支)写历史。
  history id 用 coordinator session_id,与归档 wav 文件名对齐,回放/重转才能命中。
  仅在录音确已归档时写(沿用 empty-transcript「以实际归档状态为准」语义)。
- coordinator: retranscribe_pcm —— 复用 build_qa_asr_start,用当前 provider 对一段
  PCM 重新转录,统一覆盖流式/批处理全部 provider,整段超时兜底。
- persistence: HistoryStore::update_entry,原地按 id 替换历史条目(保持位置)。
- commands/history: retranscribe_recording 命令 —— 读归档 wav→取 PCM→重转→回写
  rawTranscript/finalText 并清 error_code,返回更新后的整条记录。已注册到 lib.rs。

前端:
- ipc: retranscribeRecording。
- History.tsx: 失败条目(有 errorCode)且录音仍在时显示「重新转录」按钮,
  loading 态防重复点击,成功后局部刷新该条。
- i18n: history.retranscribe / retranscribing / retranscribeFailed(5 语言)。

仅做 ASR 重转,不自动二次润色(依赖 LLM 凭据且 issue 标为待定,留作后续)。
验证:cargo check + cargo test(481 通过)+ npm run build 均通过。

Closes #613

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

613 - Partially compliant

Compliant requirements:

  • ASR 转录失败时写入历史记录(使用 errorCode: "transcribeFailed")
  • 历史条目可播放/导出原始录音(通过现有 readAudioRecording 跨录音路径匹配)
  • 历史详情提供「重新转录」按钮,调用 retranscribeRecording IPC
  • 重新转录成功后更新 rawTranscript / finalText 并清除 error_code
  • 重新转录失败时返回错误提示,不删除原录音

Non-compliant requirements:

  • 后续润色流程未实现(重新转录后仅更新 ASR 结果,未触发 polish 流程;PR 注释中注明留作后续,但 ticket 要求包含润色)

Requires further human verification:

  • 重新转录是否沿用录音时的 ASR 提供商(当前始终使用当前配置,未确认是否为预期行为)
  • 是否需要限制重新转录次数或显示重试历史(当前未实现,但 ticket 列为待定)
⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ No major issues detected

@H-Chris233 H-Chris233 merged commit 67447e6 into beta Jun 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[asr] 转录失败时保留录音并支持在历史中重新转录

2 participants